*************************
*****Data Management*****
*************************

clear all
set more off
insheet using "study2_data.csv"
 
*treatments
tab fl_133_do
gen treatment_string = .
tostring treatment_string, replace
replace treatment_string = "Muslim neutral" if fl_133_do == "Nazitaexperiment-T1(neutral,Muslim)"
replace treatment_string = "Muslim racist" if fl_133_do == "Nazitaexperiment-T2(racist,Muslim)"
replace treatment_string = "White neutral" if fl_133_do == "NazitaexperimentT1(neutral,White)"
replace treatment_string = "White racist" if fl_133_do == "NazitaexperimentT2(racist,White)"

gen treatment =.
replace treatment = 3 if  treatment_string == "Muslim neutral"
replace treatment = 4 if  treatment_string == "Muslim racist"
replace treatment = 1 if  treatment_string == "White neutral"
replace treatment = 2 if  treatment_string == "White racist"


gen whitetreatment = .
replace whitetreatment = 1 if treatment == 1
replace whitetreatment = 1 if treatment == 2
replace whitetreatment = 0 if treatment == 3
replace whitetreatment = 0 if treatment == 4

gen neutraltreatment = .
replace neutraltreatment = 1 if treatment == 1
replace neutraltreatment = 1 if treatment == 3
replace neutraltreatment = 0 if treatment == 2
replace neutraltreatment = 0 if treatment == 4


*DVs
	*How strongly do you agree or disagree with the statement made by this Senate candidate? (higher values = more resentment)
	gen agree_sen = qid123
	recode agree 8=0 9=.25 10=.5 11=.75 12=1

	
	*If the election were held today, how likely would you be to vote for this Senate candidate? (higher values = more likely to vote)
	gen vote = qid124
	recode vote 18=1 19=.75 20=.5 21=.25 22=0
	
	
	* How would you rate the candidate on each of the following characteristics? For each one, please indicate to what extent you agree or disagree that the candidate has this attribute. (higher values = more agreemnt)
		*Truthful
		recode  qid125_1 8=1 9=2 10=3 11=4 12=5
		gen truthful = (qid125_1-1)/4
		
		*Bigoted 0-1
		tab qid125_2
		gen bigoted = qid125_2
		recode bigoted 8=0 9=.25 10=.5 11=.75 12=1
		
		*Unfair	
		gen unfair = qid125_3
		recode unfair 8=0 9=.25 10=.5 11=.75 12=1

		*Honest 0-1
		gen honest = qid125_4
		recode honest 8=0 9=.25 10=.5 11=.75 12=1

		
* Based on what you read in the article, is this politician a Democrat or a Republican?
tab qid127, gen(d)
rename d1 cand_democrat
rename d2 cand_republican	


	
*MAR Scale--this is asked post-treatment so we cannot use as moderator but could try as mediator.

*1. Most Muslim Americans integrate successfully into American culture.
*QID50_1
gen mar1 = 1+5-qid50_1

*2. Muslim Americans sometimes do not have the best interests of Americans at heart.
*QID50_2
gen mar2 = qid50_2

*3. Muslims living in the US should be subject to more surveillance than others.
*QID50_3
gen mar3 = qid50_3

*4. Muslim Americans, in general, tend to be more violent than other people
*QID50_4 
gen mar4 = qid50_4

*5. Most Muslim Americans reject jihad and violence.
*QID50_6
gen mar5 = 1+5-qid50_6

*6. Most Muslim Americans lack basic English language skills.
*QID50_7
gen mar6 = qid50_7

*7.  Most Muslim Americans are not terrorists.
*QID50_8
gen mar7 = 1+5-qid50_8

*8. Wearing headscarves should be banned in all public places.
*QID50_9
gen mar8 = qid50_9

*9. Muslim Americans do a good job of speaking out against Islamic terrorism.
*QID50_10
gen mar9 = 1+5-qid50_10

gen Postmar = (mar1+mar2+mar3+mar4+mar5+mar6+mar7+mar8+mar9)/9
sum Postmar
replace Postmar = (Postmar-`r(min)') / (`r(max)'-`r(min)')


*dehumanization
gen dehumanization = (qid32_2)/101

*Other covariates
sum age, detail

gen married = 	qid20
recode married 1=0 2=1

gen female = gender 
recode female 1=0 2=1
gen male = gender
recode male 1=1 2=0

gen income = qid17
recode income 1=1 10=2 11=3 12=4 13=5 14=6

gen income3 = qid17
recode income3 1=0 10=.2 11=.4 12=.6 13=.8 14=1

gen incomeR = (income-1)/5

gen educ = qid18
gen educR = (educ-1)/5

gen college = 1 if educ>=5

gen pid7 = qid150
recode pid7 0=1 4=1 5=2 6=3 7=4 8=5 9=6
gen pid7R = pid7/7
 
gen democrat = qid150
recode democrat 1=1 4=1 5=1 6=0 7=0 8=0 9=0
gen republican = qid150
recode republican 1=0 4=0 5=0 6=0 7=1 8=1 9=1
gen independent = qid150
recode independent 1=0 4=0 5=0 6=1 7=0 8=0 9=0

gen ideology_7pt = qid151  /*1-3 = liberal, 4 = middle of the road, 5-7 conservative*/
recode ideology_7pt 8=1 10=2 11=3 12=4 13=5 14=6 15=7
gen ideology_3pt =qid151/*-1 = liberal, 0 = middle of the road, 1 = conservative*/
recode ideology_3pt 8=-1 10=-1 11=-1 12=0 13=1 14=1 15=1

gen ideoR = (ideology_7pt-1)/6

gen race = .
tostring race, replace
replace race = "White" if qid14 == 1
replace race = "Black" if qid14 == 2
replace race = "Hispanic" if qid14 == 3
replace race = "Asian" if qid14 == 4
replace race = "Mixed Race" if qid14 == 5
replace race = "Middle Eastern" if qid14 == 6
replace race = "Native American" if qid14 == 7
replace race = "Other Race" if qid14 == 8

tab race, gen(d)
rename d1 asian
rename d2 black
rename d3 latino
rename d8 white
drop d4 d5 d6 d7
gen otherrace = .
replace otherrace = 1 if race =="Mixed Race"
replace otherrace = 1 if race =="Middle Eastern"
replace otherrace = 1 if race =="Native American"
replace otherrace = 1 if race =="Other Race"
replace otherrace = 0 if otherrace ==.

gen ageR = (age-18)/70


tab treatment_string, gen(d)
rename d1 muslimneutral
rename d2 muslimracist
rename d3 whiteneutral
rename d4 whiteracist

alpha agree_sen vote honest truthful, item
gen WM_index = (agree_sen + vote)/2
gen WM_indexChar = (truthful + honest)/2
gen WM_indexApp = ((1-bigoted) + (1-unfair))/2

drop if white == 0 
saveold "study2_cleaned.dta", version(13) replace

label var age "Age"
label var ageR "Age"
label var female "Female"
label var college "College Educated"
label var incomeR "Family Income"
label var pid7R "Party ID"
label var ideoR "Ideology"
label var Postmar "MAR"
label var dehumanization "Dehumanization"
label var treatment "Treatment"
label var WM_index "Approval"
label var WM_indexChar "Character"
label var WM_indexApp "Appropriate"

label define treatment 1 "White Neutral" 2 "White Derogator" 3 "Muslim Neutral" 4 "Muslim Derogator"
label values treatment treatment

set matsize 2000
cd ".\tables" 

estpost summarize age female college incomeR ideoR pid7R Postmar 
esttab using study2_summary.tex, cells("count mean sd min max") label noobs replace

estpost summarize WM_index WM_indexApp WM_indexChar  
esttab using study2_dvs.tex, cells("count mean sd min max") label noobs replace 


***** Summary Stats of DVs by Party
orth_out ageR female college incomeR ideoR pid7R Postmar using study2_balance.tex, by(treatment) latex se pcompare count replace


